//开始验证
	DingTalkPC.config({
			agentId : _config.agentid,
			corpId : _config.corpId,
			timeStamp : _config.timeStamp,
			nonceStr : _config.nonceStr,
			signature : _config.signature,
			jsApiList: ['device.notification.alert', 'device.notification.confirm']
		});

	//验证成功后回调
	DingTalkPC.ready(function() {
		
	    console.log("验证成功并回调");
	    
		DingTalkPC.runtime.permission.requestAuthCode({
			corpId : _config.corpId,
			onSuccess : function(info) {
				console.log('authcode: ' + info.code);
				var code = info.code;
				console.log('code: ' + code);
				$.AjaxProxy({
					a : false,
					c : false	
				}).invoke(
					basePath+"/dd/dingding/checkIsBinding?code="+code,
					function(loj){
						var status = loj.getValue("status");
						console.log(status);
						if(status == "ok"){	
							console.log("进入了ok");
							var mapInfo = loj.getValue("mapInfo");
							var ddUserId = mapInfo["ddUserId"];
							console.log("ddUserId===="+ddUserId);
							var urlok = basePath+"/common/redirect/dingding_binding?ddUserId="+ddUserId;
							console.log("urlok==="+urlok);
							openLink(urlok);
						}
						if(status == "canLogin"){
							console.log("进入了login");
							var mapInfo = loj.getValue("mapInfo");
							var ddUserId = mapInfo["ddUserId"];
							console.log("ddUserId===="+ddUserId);
							var urlLogin = basePath+"/common/redirect/dingding_login?ddUserId="+ddUserId;
							console.log("urlLogin==="+urlLogin);
							openLink(urlLogin);
						}
						if(status == "err"){
							console.log("进入了err");
							var urlerr = basePath+"/common/redirect/login";
							console.log("urlerr==="+urlerr);
							openLink(urlerr);
						}		
				})
				

			},
			onFail : function(err) {
				console.log('fail: ' + JSON.stringify(err));
			}
		});
	});

//错误回调
DingTalkPC.error(function(err) {
	console.log('dd error: ' + JSON.stringify(err));
});

//在浏览器中打开指定url
function openLink(url){	
	console.log('执行了openLink，url: ' + url);
	DingTalkPC.biz.util.openLink({
	    url: url,//要打开链接的地址
	    onSuccess : function(result) { },
	    onFail : function() {}
	})
}

function login(){
	var url = basePath + "/common/redirect/dingding_home"
//	MTools.redirect(url);
	alert(1);
	openLink(url);
}

